package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.Competitor;
import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.service.CompetitorService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class CompetitorController {
    @Autowired
    CompetitorService comService;
    @Autowired
    HttpSession session;

    // 查询竞争集合
    @RequestMapping("/competitor-list")
    @ResponseBody
    public Map<String,Object> allCompetitorList(Integer page, Integer size,Integer filter,Integer vague,String content){
        Page<Object> objects = PageHelper.startPage(page, size);
        Employee emp =(Employee) session.getAttribute("emp");
        List<Competitor> com = comService.selectCompetitor(emp.getDepartment().getDeptId(), filter,vague,content);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",com);
        map.put("total",objects.getTotal());
        return map;
    }
    // 按机会Id查询员工报价集合
    @RequestMapping("/competitor-opp-list")
    @ResponseBody
    public List<Competitor> allComOppIdList(Integer oppId){
        List<Competitor> com = comService.selectCompetitorByOppId(oppId);
        return com;
    }
    @RequestMapping("/save-competitor")
    @ResponseBody
    public void saveCompetitor(@RequestBody Competitor competitor){
        comService.saveCompetitor(competitor);
    }

    @RequestMapping("/delete-competitor")
    @ResponseBody
    public void deleteCompetitor(@RequestParam(value = "competitorId") Integer competitorId){
        comService.deleteCompetitor(competitorId);
    }
}
